﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace BDSim
{
    class StationCollectionDataProvider : BDSimDataProvider
    {
        private StationCollection _Parent;

        public StationCollection Parent
        {
            get { return _Parent; }
            set { _Parent = value; }
        }

        
        private int _InjectionStaIDNum;

        private int _MasterStaCount;
        private int _InjectionStaCount;
        private int _MonitorStaCount;
       


        #region 命令定义

        /// <summary>
        /// 新建地面站
        /// </summary>
        MenuCommand AddStationCmd = new MenuCommand();
        MenuCommand mcdDelete = new MenuCommand();

        #endregion 

        #region 命令集合初始化

        public override void DefineCommand()
        {
            AddStationCmd.Header = "新建站点";
            AddStationCmd.DefineExcuteCommand(AddStationFun_Execute, AddStationFun_CanExecute);
            MenuCommandList.Add(AddStationCmd);

            mcdDelete.Header= "删除";
            mcdDelete.DefineExcuteCommand(mcdDeleteFun_Execute, mcdDeleteFun_CanExecute);
            MenuCommandList.Add(mcdDelete);
        }

        #endregion

        #region 命令执行内容

        void AddStationFun_Execute(object param)
        {
            if (_Parent.Type == EStationType.MasterStation)
            {
                MasterStation Station1 = new MasterStation();
                _MasterStaCount++;
                Station1.Name = "MAS" + _MasterStaCount.ToString();
                Station1.Parent = this.Parent;
                Station1.Type = EStationType.MasterStation;
                _Parent.StationList.Add(Station1);
            }
            else if (_Parent.Type == EStationType.InjectionStation)
            {
                InjectionStation Station1 = new InjectionStation();
                _InjectionStaCount++;
                Station1.Name = "INJ" + _InjectionStaCount.ToString();
                Station1.Parent = this.Parent;
                Station1.Type = EStationType.InjectionStation;

                /* 注入站编号，从100开始 */
                _InjectionStaIDNum++;
                Station1.Id = 100 + _InjectionStaIDNum;

                /* 注入站添加发射接收设备 */
                SendReceiveDevice InjectSendReceive = new SendReceiveDevice();         
                InjectSendReceive.Name = "SendReceiverDevice1";
                InjectSendReceive.Parent = Station1.Parent;
                InjectSendReceive.Parent2 = Station1;
                Station1.InjectSendReceivers.Add(InjectSendReceive);

                _Parent.StationList.Add(Station1);
            }
            else if (_Parent.Type == EStationType.MonitorStation)
            {
                MonitorStation Station1 = new MonitorStation();
                _MonitorStaCount++;
                Station1.Name = "MON" + _MonitorStaCount.ToString();
                Station1.Parent = this.Parent;
                Station1.Type = EStationType.MonitorStation;

                MonitorReceiver MonitorReceiver1 = new MonitorReceiver();
                MonitorReceiver1.Name = "MONReceiver1";
                MonitorReceiver1.Parent = Station1;
                Station1.MonitorReceivers.Add(MonitorReceiver1);

                _Parent.StationList.Add(Station1);
            }
            else 
            {                
            }
 
        }
        bool AddStationFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }

        void mcdDeleteFun_Execute(object param)
        {
            Parent.Parent.GroundList.Remove(this.Parent);
        }
        bool mcdDeleteFun_CanExecute(object param)
        {
            bool flag = false;
            if (BDSimObject.GlobalStatus == ESimStatus.UnInited || BDSimObject.GlobalStatus == ESimStatus.End)
            {
                flag = true;
            }
            return flag;
        }

        #endregion

    }
}
